package com.hh.config.rocketmq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @author huanghuai
 * @date 2020/8/31
 */
public class Producer {

     // {"appId":1196271598647115800,"growthTypeId":1,"levelGroupId":9527,"levelType":0,"memberId":3,"tenantId":"gree","updateValue":1}

    public static String msg11 = "{\"appId\":999,\"tenantId\":\"huanghuai\"," +
            "\"bussinessNo\":\"9558\",\"bussinessType\":1," +
            "\"growthTypeId\":16,\"levelGroupId\":8,\"levelType\":0,\"memberId\":9527," +
            "\"serialNo\":\"1300728857585778730\",\"updateValue\":100}";

    // public static String namesrvAddr = "localhost:9876";
    public static String namesrvAddr = "10.52.32.9:9876";
    // public static String tags = "member_growth_changed";
    public static String tags = "compute-level-tag";
    public static String topic = "DEEPEXI_DOMAIN_MEMBER";
    public static void main(String[] args) throws Exception{


        //Instantiate with a producer group name.
        DefaultMQProducer producer = new  DefaultMQProducer("please_rename_unique_group_name");
        // Specify name server addresses.
        producer.setNamesrvAddr(namesrvAddr);
        //Launch the instance.
        producer.start();
        for (int i = 0; i < 1; i++) {
            //Create a message instance, specifying topic, tag and message body.
            Message msg = new Message(topic,
                    tags ,
                    "key"+i,
                    msg11.getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */);
            //Call send message to deliver message to one of brokers.
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
        //Shut down once the producer instance is not longer in use.
        producer.shutdown();
    }
}
